#!/bin/bash

export PYTHONPATH=${HOME}/install/apache-tomcat-5.5.15/webapps/isso/WEB-INF/classes/net/amsoft/iservice/isso/python:${HOME}/install/openid
#:${HOME}/install/openid/usr/lib/python2.4/site-packages
#export LDPATH=${HOME}/install/openid/usr/lib/python2.4/site-packages

# IP of the host where openid is to be run
HOST_IP=localhost
# The listening port foropenid 
HOST_PORT=8001
#Name of the file to be run to start the openid server
SERVER_FILE=server.py
#Command to run the python on this machine, may include path to command
PYTHON_CMD=python
#The path of the file to be used to run the openid server
OPENID_SERVER_DIR=${HOME}/install/apache-tomcat-5.5.15/webapps/isso/WEB-INF/classes/net/amsoft/iservice/isso/python/amsoftopenid/

#Usage is : openid_server.sh stop/start
case "$1" in
    start)
	cd ${OPENID_SERVER_DIR}
	${PYTHON_CMD} ${SERVER_FILE} --host ${HOST_IP} --port ${HOST_PORT} &
	sleep 3
    ;;
    stop)
		ps -ef | grep ${SERVER_FILE} | grep -v "grep" | awk -F" " '{ print $2; }' | xargs kill
    ;;
	*)
		echo "Usage: $0 {start|stop}"
		exit 1
	;;
esac
